(function (line) {
    var elementMap = {};

    line.extend(line, {
        wrapElement:function (el) {
            var tagName = el.tagName.toLowerCase();
            var element;
            if (tagName == 'input' || tagName == 'textarea') {
                element = new line.InputElement(el);
            }
            else {
                element = new line.Element(el);
            }

            return element;
        },
        parse:function (el) {
            var bindingsAttr = el.getAttribute('data-bindings');
            if (bindingsAttr) {
                var bindings = JSON.parse(bindingsAttr);
                var element = line.wrapElement(el);

                line.each(bindings, function (binding) {
                    var sourceName = binding.source;
                    if (sourceName) {
                        var source = null;
                        if (elementMap[sourceName]) {
                            source = elementMap[sourceName];
                        }
                        else {
                            var sourceEl = document.getElementById(sourceName);
                            if (sourceEl) {
                                source = elementMap[sourceName] = line.wrapElement(sourceEl);
                            }
                        }

                        element.setBinding(binding.prop, binding.path, source);
                    }
                });
            }

            var child = el.firstElementChild;
            while (child) {
                line.parse(child);
                child = child.nextElementSibling;
            }
        }
    });

    window.onload = function () {
        line.parse(document.body);
    };
})(line);
